<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateSanitationTasksTable extends Migration
{
    /**
     * Run the migrations.
     *环卫管理->任务管理
     *
     * @return void
     */
    public function up()
    {
        Schema::create('sanitation_tasks', function (Blueprint $table) {
            $table->increments('id');
            $table->string('task_name')->comment('任务名称');
            $table->integer('task_category_id')->unsigned()->comment('任务类型')->nullable();
            $table->foreign('task_category_id')->references('id')->on('task_categories')->onDelete('set null');
            $table->string('task_content')->comment('任务内容')->nullable();
            $table->string('task_address')->comment('任务地址')->nullable();
            $table->polygon('task_areas')->comment('任务区域')->nullable();
            $table->integer('department_id')->unsigned()->comment('任务部门id')->nullable();
            $table->foreign('department_id')->references('id')->on('departments')->onDelete('set null');
            $table->string('post_ids')->comment('岗位id字符串 如1,2')->nullable();
            // $table->foreign('post_id')->references('id')->on('posts')->onDelete('set null');
            $table->integer('task_principal_id')->unsigned()->comment('任务负责人id')->nullable();
            $table->foreign('task_principal_id')->references('id')->on('employees')->onDelete('set null');
            $table->integer('task_publisher_id')->unsigned()->comment('任务发布人id')->nullable();
            $table->foreign('task_publisher_id')->references('id')->on('employees')->onDelete('set null');
            // $table->text('task_plan')->comment('任务安排 json格式数据')->nullable();
            $table->bigInteger('car_id')->unsigned()->comment('任务车辆id')->nullable();
            $table->foreign('car_id')->references('id')->on('cars')->onDelete('set null');
            $table->timestamp('task_begin_time')->comment('任务开始时间')->nullable();
            $table->timestamp('task_end_time')->comment('任务结束时间')->nullable();
            $table->integer('task_level')->unsigned()->comment('紧急程度  1-一级 2-二级 3-三级')->default(3);
            $table->string('task_source')->comment('任务来源')->nullable();
            $table->integer('task_status')->comment('任务状态 0=待完成 1=待反馈 2=已经反馈 3=已完成')->default(0);
            $table->string('step')->comment('处理措施')->nullable();
            $table->string('task_tool')->comment('工具')->nullable();
            $table->string('staff')->comment('出勤人员 如:1,2,3')->nullable();
            $table->string('remark')->comment('备注')->nullable();
            $table->softDeletes();
            $table->timestamps();
        });

        Schema::create('sanitation_task_files', function (Blueprint $table) {
            //字段定义
            $table->increments('id');
            $table->integer('sanitation_task_id')->unsigned()->comment('环卫任务id')->nullable();
            $table->foreign('sanitation_task_id')->on('sanitation_tasks')->references('id')->onDelete('set null');
            $table->BigInteger('file_id')->unsigned()->comment('图片所属的文件信息')->nullable();
            $table->foreign('file_id')->on('file_upload')->references('id')->onDelete('set null');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('sanitation_task_files');
        Schema::dropIfExists('sanitation_tasks');
    }
}
